/**
 * 将虚拟节点转换为真实节点
 * @param {虚拟节点} vnode
 */
export function createElement(vnode) {
  //根据虚拟节点创建对应dom节点
  let domNode = document.createElement(vnode.sel);
  //子节点有文本
  if (
    vnode.text !== "" &&
    (vnode.children === undefined || vnode.children.length === 0)
  ) {
    domNode.innerText = vnode.text;
  } else if (Array.isArray(vnode.children) && vnode.children.length > 0) {
    for (let i = 0; i < vnode.children.length; i++) {
      let ch = vnode.children[i];
      let chDom = createElement(vnode.children[i]);
      domNode.appendChild(chDom);
    }
  }
  vnode.elm = domNode;
  return vnode.elm;
}
